import {
    _decorator,
    AssetManager,
    Component,
    Node,
    TextAsset,
    WebView,
} from 'cc';
import { PREVIEW } from 'cc/env';
const { ccclass, property } = _decorator;

@ccclass('WebViewEvent')
export class WebViewEvent extends Component {
    @property(WebView)
    frame: WebView = null!;

    start() {
        AssetManager.instance.loadBundle('web', (err, data) => {
            if (err) {
                console.error(err);
                return;
            }
            const bundle = data;
            bundle.load('frame', TextAsset, (err, data) => {
                if (err) {
                    console.error(err);
                    return;
                }
                if (PREVIEW) {
                } else {
                    this.frame.url = data.nativeUrl;
                    this.frame.node.active = true;
                    console.log(data.nativeUrl);
                    console.log(data.text);
                }
            });
        });
    }

    update(deltaTime: number) {}
}
